
import { defineStore } from 'pinia'
import { collectionEditDetailType } from '../utils/trueType'
import { collectionEditSubmit } from '../utils/trueType'

export const useDialogStore = defineStore('dialog', {
    state: () => ({
        contain: {
            id: null,
            internalId: '',
            name: '',
            alternateName: '',
            classificationId: null,
            period:'',
            description: '', // 初始化默认值
            preservationStatus: '',
            weight: null,
            currentLocation: '',
            status: '',
            updatedAt: null,
            img: ''
        } as collectionEditDetailType,
        containEdit:{
            id: null,
            internalId: '',
            name: '',
            alternateName: '',
            classificationId: null,
            eraId: null,
            description: '', // 初始化默认值
            preservationStatus: '',
            weight: null,
            currentLocation: '',
            status: '',
            updatedAt: null,
            img: '',
        } as collectionEditSubmit,
        dialog: false,
        isSubmit: false,
    }),
    actions: {
        setContain(contain: collectionEditDetailType) {
            Object.assign(this.contain, JSON.parse(JSON.stringify(contain)))
        },
        setContainNull() {
            Object.assign(this.contain, JSON.parse(JSON.stringify({
                id: null,
                internalId: '',
                name: '',
                alternateName: '',
                classificationId: null,
                eraId: null,
                description: '', // 初始化默认值
                preservationStatus: '',
                weight: null,
                currentLocation: '',
                status: '',
                updatedAt: null,
                img: '',
            })))
        },
        setContainEdit(containEdit: collectionEditSubmit,contain: collectionEditDetailType) {
            containEdit.id= contain.id
            containEdit.classificationId= contain.classificationId
            containEdit.internalId= contain.internalId
            containEdit.name= contain.name
            containEdit.alternateName= contain.alternateName
            containEdit.description= contain.description
            containEdit.preservationStatus= contain.preservationStatus
            containEdit.weight= contain.weight
            containEdit.currentLocation= contain.currentLocation
            containEdit.status= contain.status
            containEdit.img= contain.img
            Object.assign(this.containEdit, JSON.parse(JSON.stringify(containEdit)))
        },
        setDialog() {
            this.dialog = !this.dialog
        },
        changeDescription(description: string) {
            this.contain.description = description
        },
        setImg(img) {
            this.contain.img = img
        },
        changeIsSubmit() {
            this.isSubmit = !this.isSubmit
        },
        setIsSubmit(isSubmit: boolean) {
            this.isSubmit = isSubmit
        },
    },
    getters: {

    },
}
)